﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Shapes;

namespace App40
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            this._Stopwatch.Start();
        }

        Stopwatch _Stopwatch = new Stopwatch();

        MainPageViewModel ViewModel { get { return this.DataContext as MainPageViewModel; } }

        private void ScrollViewer_ViewChanging(object sender, ScrollViewerViewChangingEventArgs e)
        {
            this.ViewModel.ChangingTraces.Insert(0, string.Format("Changing {1}, {0}", this._Stopwatch.ToString(), e.IsInertial));
            if (!e.IsInertial)
                this.ViewModel.ChangingTraces.Insert(0, "-ended-");
        }

        private void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
        {
            this.ViewModel.ChangedTraces.Insert(0, string.Format("Changed {1}, {0}", this._Stopwatch.ToString(), e.IsIntermediate));
            if (!e.IsIntermediate)
                this.ViewModel.ChangedTraces.Insert(0, "-ended-");
        }
    }

    public class MainPageViewModel
    {
        public MainPageViewModel()
        {
            this.Items = Enumerable.Range(0, 100).ToArray();
            this.ChangedTraces.Add("First trace");
            this.ChangedTraces.Add("Second trace");
            this.ChangingTraces.Add("First trace");
            this.ChangingTraces.Add("Second trace");
        }

        public int[] Items { get; set; }

        ObservableCollection<string> _ChangedTraces = new ObservableCollection<string>();
        public ObservableCollection<string> ChangedTraces { get { return _ChangedTraces; } }

        ObservableCollection<string> _ChangingTraces = new ObservableCollection<string>();
        public ObservableCollection<string> ChangingTraces { get { return _ChangingTraces; } }
    }
}
